"""
## 课后作业

- 给定一个列表, 根据`grade`来排序

  ```
  classes = [
      {"name": "n_1", "age": 24, "grade": "A"},
      {"name": "n_2", "age": 23, "grade": "B"},
      {"name": "n_3", "age": 28, "grade": "A"},
      {"name": "n_4", "age": 24, "grade": "A"},
      {"name": "n_5", "age": 25, "grade": "C"},
      {"name": "n_6", "age": 21, "grade": "D"},
      {"name": "n_7", "age": 27, "grade": "A"},
  ]
  ```

- 通过`filter`语句来筛选出`Grade`为`A`的同学

- 通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda)

- 使用递归函数重构斐波那契函数

  ```
  f(n) = f(n-1) + f(n-2)
  ```
"""

classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes = sorted(classes, key=lambda x: x['grade'])
print(classes)

f = filter(lambda x: x['grade'] == "A", classes)
print(list(f))

"""
不会
"""
m = map(lambda x: x['age'] + 1, classes)
print(list(m))

"""
f(n) = f(n-1) + f(n-2)
eg：
def fact(n):
      if n == 1:
          return 1
      return n * fact(n-1)
      
1,1,2,3,5,8,13
1,2,3,4,5,6,7,
"""
def feibonaqie(n):
    if n<=1:
        return 1
    return feibonaqie(n-1)+feibonaqie(n-2)

for i in range(2):
    feibonaqie(i)
    print(feibonaqie(i))


print("=================================")
def fun(n):
    if n==1:
        return [0]
    elif n==2:
        return [0,1]
    l=[0,1]
    for i in range(2,n):
        l.append(l[-2]+l[-1])
        return l
print(fun(3))